package bird.spring.com.designpattern.RoomDemo;

import java.util.List;

/**
 * Created by co-mall on 2015/12/7.
 */
public class Tenant {
    public float roomArea;
    public float roomPrice;
    public final float diffPrice = 100.0001f;
    public final float diffArea = 0.00001f;

    public void rentRoom(Mediator mediator) {
        List<Room> rooms = mediator.getAllRooms();
        for (Room room : rooms) {
            if (isSuitable(room)) {
                System.out.println("租到房间啦! " + room);
                break;
            }
        }
    }

    private boolean isSuitable(Room room) {
        return Math.abs(room.price - roomPrice) < diffPrice
                && Math.abs(room.area - roomArea) < diffArea;
    }


    public void myRentRoom(MyMediator myMediator) {
        myMediator.rentOut(roomArea, roomPrice, diffPrice, diffArea);
    }
}
